package com.yz.rabbitmq.exchange.direct;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.yz.rabbitmq.ChannelsUtil;

import java.io.IOException;

/**
 * 描述：
 **/
public class DirectExchangeCon {
    public static void main(String[] args) {
        Channel channel = ChannelsUtil.getChannel();
                try {
                    channel.exchangeDeclare("directExchange","direct",true);
                    channel.queueDeclare("directQueue1",true,false,false,null);
                    channel.queueBind("directQueue1","directExchange","direct");
                    channel.basicConsume("directQueue1",false,new DefaultConsumer(channel){
                        @Override
                        public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                            System.out.println(new String(body));
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    //ChannelsUtil.closeChannel(channel);
                }
    }
}
